﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HRM.HRMServiceProxy;
using WeifenLuo.WinFormsUI.Docking;
using HRM.Utilities;

namespace HRM
{
    public partial class frmMessageBoard : DockContent
    {
        EmployeeClient wcfEmployee;
        int pageSize = UIParamater.pageSize;
        int currPage = 0;
        int itemCount = 5;
        int totalPage = 0;
        int department_ID = 0;
        int branch_ID = 0;
        int _dayVal = 15;
        int _Total = 0;

        public event ShowDock ShowDockEvent;
        private string _frmName = "";
        int _day = 0;
        public string FrmName
        {
            get { return _frmName; }
            set { _frmName = value; }
        }
        public frmMessageBoard(int BranchID)
        {
            InitializeComponent();
            wcfEmployee = Service.Employee();
            branch_ID = BranchID;
            BuildSalary();
            //BuildPosition();
            BuildContract();
            BuildContractEnd();
            BuildNoContract();
            //BuildProbation();
            //BuildSpecial();
            LoadSalary();//Sap tang luong
            //LoadPosition();//Sap bo nhiem lai
            LoadContract();//Sap het han HD
            LoadContractEnd();//Het han HD
            //LoadProbation();//Sap het han thu viec
            LoadNoContract();//Khong co HD
            //LoadSpecial();//Nhan vien DB
        }
        private void BuildSalary()
        {
            UISetting.AddColumn(ref dgvSalary, "Employee_FullName", UpdateUI.GetString("hovaten"), "", 150, true, true);
        }
        void LoadSalary()
        {
            DataSet _ds = wcfEmployee.Employee_IncreaseSalary(out itemCount, _dayVal, branch_ID, department_ID, DateTime.Now, currPage, pageSize, 1);
            dgvSalary.Rows.Clear();
            for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
            {
                dgvSalary.Rows.Insert(i, 1);
                dgvSalary.Rows[i].Cells["Employee_FullName"].Value = _ds.Tables[0].Rows[i]["Employee_LastName"].ToString()
                    + " " + _ds.Tables[0].Rows[i]["Employee_FirstName"].ToString();
            }
            lblSalary.Text = "Sắp tăng lương: " + itemCount.ToString();
        }
        //private void BuildPosition()
        //{
        //    UISetting.AddColumn(ref dgvPosition, "Employee_FullName", UpdateUI.GetString("hovaten"), "", 150, true, true);
        //}
        //private void LoadPosition()
        //{
        //    DataSet _ds = wcfEmployee.Employee_IncreaseSalary(out itemCount, _dayVal, branch_ID, department_ID, DateTime.Now, currPage, pageSize, 2);
        //    dgvPosition.Rows.Clear();
        //    for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
        //    {
        //        dgvPosition.Rows.Insert(i, 1);
        //        dgvPosition.Rows[i].Cells["Employee_FullName"].Value = _ds.Tables[0].Rows[i]["Employee_LastName"].ToString()
        //            + " " + _ds.Tables[0].Rows[i]["Employee_FirstName"].ToString();
        //    }
        //    lblPosition.Text = "Sắp bổ nhiệm lại: " + dgvPosition.RowCount.ToString();
        //}
        private void BuildContractEnd()
        {
            UISetting.AddColumn(ref dgvContractEnd, "Employee_FullName", UpdateUI.GetString("hovaten"), "", 150, true, true);
        }
        private void LoadContractEnd()
        {
            DataSet ds = wcfEmployee.Employee_GetLabourContract(out itemCount, out _Total, _day, DateTime.Now, 1, "", "ASC", currPage, pageSize, branch_ID, department_ID);
            dgvContractEnd.Rows.Clear();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dgvContractEnd.Rows.Insert(i, 1);
                dgvContractEnd.Columns["Employee_FullName"].Frozen = true;
                dgvContractEnd.Rows[i].Cells["Employee_FullName"].Value = ds.Tables[0].Rows[i]["Employee_FullName"].ToString();
            }
            lblContractEnd.Text = "Hết hạn hợp đồng: " + itemCount.ToString();
        }
        private void BuildContract()
        {
            UISetting.AddColumn(ref dgvContract, "Employee_FullName", UpdateUI.GetString("hovaten"), "", 150, true, true);
        }
        private void LoadContract()
        {
            DataSet ds = wcfEmployee.Employee_GetLabourContract(out itemCount, out _Total, _day, DateTime.Now, 2, "", "ASC", currPage, pageSize, branch_ID, department_ID);
            dgvContract.Rows.Clear();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dgvContract.Rows.Insert(i, 1);
                dgvContract.Columns["Employee_FullName"].Frozen = true;
                dgvContract.Rows[i].Cells["Employee_FullName"].Value = ds.Tables[0].Rows[i]["Employee_FullName"].ToString();
            }
            lblContract.Text = "Sắp hết hạn hợp đồng: " + itemCount.ToString();
        }
        //private void BuildProbation()
        //{
        //    UISetting.AddColumn(ref dgvProbation, "Employee_FullName", UpdateUI.GetString("hovaten"), "", 150, true, true);
        //}
        //private void LoadProbation()
        //{
        //    DataSet ds = wcfEmployee.Employee_GetLabourContract(out itemCount, out _Total, _day, DateTime.Now, 4, "", "ASC", currPage, pageSize, branch_ID);
        //    dgvProbation.Rows.Clear();
        //    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //    {
        //        dgvProbation.Rows.Insert(i, 1);
        //        dgvProbation.Columns["Employee_FullName"].Frozen = true;
        //        dgvProbation.Rows[i].Cells["Employee_FullName"].Value = ds.Tables[0].Rows[i]["Employee_FullName"].ToString();
        //    }
        //    lblProbation.Text = "Sắp hết hạn thử việc: " + dgvProbation.RowCount.ToString();
        //}
        private void BuildNoContract()
        {
            UISetting.AddColumn(ref dgvNoContract, "Employee_FullName", UpdateUI.GetString("hovaten"), "", 150, true, true);
        }
        private void LoadNoContract()
        {
            DataSet ds = wcfEmployee.Employee_GetLabourContract(out itemCount, out _Total, _day, DateTime.Now, 3, "", "ASC", currPage, pageSize, branch_ID, department_ID);
            dgvNoContract.Rows.Clear();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dgvNoContract.Rows.Insert(i, 1);
                dgvNoContract.Columns["Employee_FullName"].Frozen = true;
                dgvNoContract.Rows[i].Cells["Employee_FullName"].Value = ds.Tables[0].Rows[i]["Employee_FullName"].ToString();
            }
            lblNoContract.Text = "Chưa có hợp đồng: " + itemCount.ToString();
        }
        //private void BuildSpecial()
        //{
        //    UISetting.AddColumn(ref dgvSpecial, "Employee_FullName", UpdateUI.GetString("hovaten"), "", 150, true, true);
        //}
        //private void LoadSpecial()
        //{
        //    DataSet ds = wcfEmployee.Employee_GetLabourContract(out itemCount, out _Total, _day, DateTime.Now, 6, "", "ASC", currPage, pageSize, branch_ID);
        //    dgvSpecial.Rows.Clear();
        //    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        //    {
        //        dgvSpecial.Rows.Insert(i, 1);
        //        dgvSpecial.Columns["Employee_FullName"].Frozen = true;
        //        dgvSpecial.Rows[i].Cells["Employee_FullName"].Value = ds.Tables[0].Rows[i]["Employee_FullName"].ToString();
        //    }
        //    lblSpecial.Text = "Sắp hết hạn hợp đồng (NV đặc biệt): " + dgvSpecial.RowCount.ToString();
        //}
        private void lblPosition_Click(object sender, EventArgs e)
        {
            if (ShowDockEvent != null)
                ShowDockEvent("frmUpdatePositionList");
        }

        private void lblSalary_Click(object sender, EventArgs e)
        {
            if (ShowDockEvent != null)
                ShowDockEvent("frmIncreaseSalaryList");
        }

        private void lblContract_Click(object sender, EventArgs e)
        {
            if (ShowDockEvent != null)
                ShowDockEvent("frmEmployeeLCNearInvalidList");
        }

        private void lblContractEnd_Click(object sender, EventArgs e)
        {
            if (ShowDockEvent != null)
                ShowDockEvent("frmEmployeeLCInvalidList");
        }

        private void lblProbation_Click(object sender, EventArgs e)
        {
            if (ShowDockEvent != null)
                ShowDockEvent("frmEmployeeLCNearProbationInvalidList");
        }

        private void lblNoContract_Click(object sender, EventArgs e)
        {
            if (ShowDockEvent != null)
                ShowDockEvent("frmEmployeeNoLCList");
        }

        private void lblSpecial_Click(object sender, EventArgs e)
        {
            if (ShowDockEvent != null)
                ShowDockEvent("frmEmployeeLCInvalidSpecialList");
        }

        private void lblNoContract_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

        }



    }
}
